package com.example.zyfypt_206shj.model;

import android.support.v7.app.AppCompatActivity;
import android.widget.Toast;

import com.example.zyfypt_206shj.activity.activity_main;
import com.example.zyfypt_206shj.bean.UserInfo;
import com.example.zyfypt_206shj.iface.LogoutIface;
import com.example.zyfypt_206shj.service.LogoutService;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by Raindy on 2017/4/14.
 */

public class LogoutModel extends AppCompatActivity implements LogoutIface {
    private Retrofit retrofit;
    private String BASEURL="http://amicool.neusoft.edu.cn/";
    private LogoutService logoutService;

    public LogoutModel() {
        retrofit = new Retrofit.Builder().baseUrl(BASEURL).addConverterFactory(GsonConverterFactory.create()).build();
    }

    @Override
    public void doLogout(String SessionID) {
        logoutService = retrofit.create(LogoutService.class);
        Call<String> call = logoutService.logout(SessionID);
        call.enqueue(new Callback<String>() {
            @Override
            public void onResponse(Call<String> call, Response<String> response) {
                if(response.isSuccessful()){
                    Toast.makeText(getApplicationContext(), "您已退出登录.", Toast.LENGTH_SHORT).show();
                    finish();
                }
                else
                    Toast.makeText(getApplicationContext(), "What's up?", Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onFailure(Call<String> call, Throwable t) {
                Toast.makeText(getApplicationContext(), "退出登录失败.", Toast.LENGTH_SHORT).show();
            }
        });
    }
}

